Skip to content

🤡 workaround for path-dependent pyright bug by replicating CanArrayND #742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

jorenham
Copy link
Member

This works around a Pyright bug where it reports false positives if run as e.g. pyright tests, instead of just pyright .. I believe this is the same bug as the one in that from #741.

The bug seems to have to do with type parameter defaults: It has to do with generic protocols that have generic type arguments, that sometimes (depending on the order of analysis) falsely reject assignment to it.
This is the case for optype.nunpy.CanArray, which has two type parameters with defaults. When running pyright tests, Pyright sometimes incorrectly does not allow assigning compatible np.ndarray instances to this CanArray protocol. I've only seen this occur in overloads, but I'm not sure if that's relevant here.

Either way, I worked around this by replacing the optype.numpy.CanArray with a custom scipy._typing.CanArray protocol, that's almost equivelent, apart from its first type parameter not having a default. I.e. it has two type parameters, and only one of them has a default.

Note that currently, even without this PR, pyright . works fine, and so does pyright scipy-stubs, and pyright scipy-stubs tests. But without this workaround, pyright tests and pyright tests scipy-stubs will report false positive errors.

I'm not sure if I'm going to merge this, as I'm not sure whether the mess this causes is worth it.

@JulVandenBroeck
Copy link
Contributor

I looked into this PR and I notice the same difference in behavior for pyright . vs. pyright tests in #733; no problems in the first case...
I'll have to wait until this PR is merged, I guess :)

@jorenham
Copy link
Member Author

closing in favor of #745

@jorenham jorenham closed this Jul 15, 2025
@jorenham jorenham deleted the pyright-path-dependent-bug-workaround branch July 15, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants